package com.ruoyi.mall.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.domain.vo.GoodsSpecificationsDetailVo;
import com.ruoyi.mall.domain.bo.GoodsSpecificationsDetailBo;
import com.ruoyi.mall.service.IGoodsSpecificationsDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品规格明细
 *
 * @author ruoyi
 * @date 2024-04-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/specificationsDetail")
public class GoodsSpecificationsDetailController extends BaseController {

    private final IGoodsSpecificationsDetailService iGoodsSpecificationsDetailService;

    /**
     * 查询商品规格明细列表
     */
    @SaCheckPermission("mall:specificationsDetail:list")
    @GetMapping("/list")
    public TableDataInfo<GoodsSpecificationsDetailVo> list(GoodsSpecificationsDetailBo bo, PageQuery pageQuery) {
        return iGoodsSpecificationsDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出商品规格明细列表
     */
    @SaCheckPermission("mall:specificationsDetail:export")
    @Log(title = "商品规格明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GoodsSpecificationsDetailBo bo, HttpServletResponse response) {
        List<GoodsSpecificationsDetailVo> list = iGoodsSpecificationsDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "商品规格明细", GoodsSpecificationsDetailVo.class, response);
    }

    /**
     * 获取商品规格明细详细信息
     *
     * @param goodsSpecificationsDetailId 主键
     */
    @SaCheckPermission("mall:specificationsDetail:query")
    @GetMapping("/{goodsSpecificationsDetailId}")
    public R<GoodsSpecificationsDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long goodsSpecificationsDetailId) {
        return R.ok(iGoodsSpecificationsDetailService.queryById(goodsSpecificationsDetailId));
    }

    /**
     * 新增商品规格明细
     */
    @SaCheckPermission("mall:specificationsDetail:add")
    @Log(title = "商品规格明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GoodsSpecificationsDetailBo bo) {
        return toAjax(iGoodsSpecificationsDetailService.insertByBo(bo));
    }

    /**
     * 修改商品规格明细
     */
    @SaCheckPermission("mall:specificationsDetail:edit")
    @Log(title = "商品规格明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GoodsSpecificationsDetailBo bo) {
        return toAjax(iGoodsSpecificationsDetailService.updateByBo(bo));
    }

    /**
     * 删除商品规格明细
     *
     * @param goodsSpecificationsDetailIds 主键串
     */
    @SaCheckPermission("mall:specificationsDetail:remove")
    @Log(title = "商品规格明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{goodsSpecificationsDetailIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] goodsSpecificationsDetailIds) {
        return toAjax(iGoodsSpecificationsDetailService.deleteWithValidByIds(Arrays.asList(goodsSpecificationsDetailIds), true));
    }
}
